package com.kexinde.wjifen.util;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;
/**
 * ��ҳDAO
 * @author vincent
 *
 */
@Component("pageDAO")
public class Page {
	private HibernateTemplate hibernateTemplate;

	public int countRecord(String table) { // �����ܼ�¼��
		return Integer.parseInt(String.valueOf(hibernateTemplate.find(
				"select count(*) from " + table).get(0)));
	}

	public List<Object> pageList(final int firstR, final int maxR,final String table) { //����ָ����¼��

		return this.getHibernateTemplate().executeFind(
				new HibernateCallback() {

					@Override
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						Query q = session.createQuery("from "+table);
						q.setFirstResult(firstR);
						q.setMaxResults(maxR);
						return q.list();
					}

				});
	}

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}
	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}


}
